﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class Q1SwClick : MonoBehaviour, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler
{
    public Texture2D TargetCursor;
    public AudioClip SwAction;
    public GameObject Q1ON;
    public GameObject Q1OFF;
    public Renderer ledRenderer;

    Text Notice;
    // Use this for initialization
    void Start () {
		SwAction= Resources.Load("Audio/switch", typeof(AudioClip)) as AudioClip;
        Q1ON = GameObject.Find("Q1ON_SW");
        Q1OFF = GameObject.Find("Q1OFF_SW");
        ledRenderer=GameObject.Find("H3_red").GetComponent<Renderer>();
    }
	
	// Update is called once per frame
	void Update () {
		
	}

    public void OnPointerClick(PointerEventData eventData)
    {
        AudioSource.PlayClipAtPoint(SwAction, this.transform.position);
        /*按钮关闭动画*/

        Global.Q1Status=!Global.Q1Status;
        Q1ON.GetComponent<Renderer>().enabled = Global.Q1Status;
        Q1OFF.GetComponent<Renderer>().enabled =!Global.Q1Status;
        if (Global.RunStatus == 0 && Global.Q1Status == true)
        {
            ledRenderer.material.color = new Color(1f, 0, 0, 255);
        }
        else
        {
            ledRenderer.material.color = new Color(0.5f, 0, 0, 255);
        }
        Debug.Log(Global.Q1Status);
    }

    public void OnPointerEnter(PointerEventData eventData)
    {
        //把鼠标指针改为ClickedCursorImg
        TargetCursor = Resources.Load("Cursor/hand1", typeof(Texture2D)) as Texture2D;
        Cursor.SetCursor(TargetCursor, Vector2.zero, CursorMode.Auto);
    }

    public void OnPointerExit(PointerEventData eventData)
    {
        // 重置鼠标指针图标
        Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
    }

}
